package com.xc.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xc.pojo.Dept;
import com.xc.pojo.Floor;
import com.xc.service.FloorService;
import com.xc.utils.DataGridViewResult;
import com.xc.utils.SysConstants;
import com.xc.vo.DeptVo;
import com.xc.vo.FloorVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/admin/floor")
public class FloorController {
    @Autowired
    private FloorService floorService;

    /**
     *  查询部门列表
     * @param floorVo
     * @return
     */
    @RequestMapping("/list")
    public DataGridViewResult list(FloorVo floorVo){
        //设置分页信息(当前页码,每页显示数量)
        PageHelper.startPage(floorVo.getPage(),floorVo.getLimit());
        //调用分页查询列表的方法
        List<Floor> floorList = floorService.queryFloorList(floorVo);
        //创建分页对象
        PageInfo<Floor> pageInfo=new PageInfo<Floor>(floorList);
        //返回数据
        return new DataGridViewResult(pageInfo.getTotal(),pageInfo.getList());
    }

    /**
     * 添加楼层
     * @param floor
     * @return
     */
    @RequestMapping("/addFloor")
    public String addFloor(Floor floor){
        HashMap<String, Object> map = new HashMap<String, Object>();
        if (floorService.addFloor(floor)>0){
            map.put(SysConstants.SUCCESS,true);
            map.put(SysConstants.MESSAGE,"添加成功");
        }else {
            map.put(SysConstants.SUCCESS,false);
            map.put(SysConstants.MESSAGE,"添加失败");
        }
        return JSON.toJSONString(map);
    }

    /**
     * 修改楼层
     * @param floor
     * @return
     */
    @RequestMapping("/updateFloor")
    public String updateFloor(Floor floor){
        HashMap<String, Object> map = new HashMap<String, Object>();
        if (floorService.updateFloor(floor)>0){
            map.put(SysConstants.SUCCESS,true);
            map.put(SysConstants.MESSAGE,"添加成功");
        }else {
            map.put(SysConstants.SUCCESS,false);
            map.put(SysConstants.MESSAGE,"添加失败");
        }
        return JSON.toJSONString(map);
    }
    /**
     * 查询楼层列表数据
     * @return
     */
    @RequestMapping("/floorList")
    public String floorList(){
        return floorService.queryFloorListByRedis();
    }
}
